﻿namespace drinking.Api
{
    /// <summary>
    /// 封装接口的统一响应格式
    /// </summary>
    public class ApiResult
    {
        /// <summary>
        /// 响应码  成功：1 , 失败：其他
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 响应信息提示
        /// </summary>
        public string Msg { get; set; } = "";

        /// <summary>
        /// 响应数据
        /// </summary>
        public Object? Data { get; set; }


        public static ApiResult Success() => ApiResult.Success(null);

        public static ApiResult Success(Object? data) => new ApiResult {Code = ResultCode.OK, Data = data };

        public static ApiResult Fail(string msg) => ApiResult.Fail(ResultCode.NO_OK, msg );

        public static ApiResult Fail(int code, string msg) => new ApiResult { Code = code, Msg = msg };



    }

    /// <summary>
    /// ApiResult 中的返回码
    /// </summary>
    public class ResultCode
    {
        /// <summary>
        /// 接口成功
        /// </summary>
        public static readonly int OK = 1;

        /// <summary>
        /// 未登录
        /// </summary>
        public static readonly int NO_LOGON = 5;

        /// <summary>
        /// 未预见的异常
        /// </summary>
        public static readonly int ERROR = 4;

        /// <summary>
        /// 接口成功
        /// </summary>
        public static readonly int NO_OK = 2;
    }

}